#include "../begonia.h"
#include "cselect.h"

const int leveln=3;
const int stagen[]={7,3,2};
const char *selects[][20]={
	{
    "LEVEL 1-1",
    "LEVEL 1-2",
    "LEVEL 1-3",
    "LEVEL 1-4",
    "LEVEL 1-5",
    "LEVEL 1-6",
    "LEVEL 1-0"
	},{
    "LEVEL 2-2",
    "LEVEL 2-3",
    "LEVEL 2-4"
	},{
    "LEVEL 3-1",
	"LEVEL 3-2"
	}
};

void cselect::display(void)
{
    glClear(GL_COLOR_BUFFER_BIT);
    glViewport(scx,scy,scw,sch);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0,scw,0,sch, -1.0, 1.0);
	glMatrixMode(GL_MODELVIEW);
    glColor3d(0.7,0.3,0.3);
    glBegin(GL_POLYGON);
        glVertex2d(0,0);
        glVertex2d(scw,0);
        glVertex2d(scw,sch);
        glVertex2d(0,sch);
    glEnd();
    glColor3d(1.0,1.0,1.0);
    for(int i=0;i<stagen[level];i++)
    {
        drawstring(scw/2.0,sch/2.0-16.0*i,selects[level][i],0.5);
    }
    glColor3d(1.0,1.0,0.0);
    drawstring(scw/2.0,sch/2.0-16.0*stage,selects[level][stage],0.5);
    drawstring(scw/2.0-1.0,sch/2.0-16.0*stage,selects[level][stage],0.5);
    glutSwapBuffers();
}

void cselect::key(unsigned char key, int x, int y)
{
    switch (key)
    {
        case 'a':
            ai=true;
            break;
        case 's':
            ai=false;
            break;

        case 'z': case 'Z':
            init();
        break;
    }
    glutPostRedisplay();
}

void cselect::specialkey(int key, int x, int y)
{
    switch (key)
    {
        case GLUT_KEY_UP:
            stage=(stage+stagen[level]-1)%stagen[level];
            break;
        case GLUT_KEY_DOWN:
            stage=(stage+1)%stagen[level];
            break;
        case GLUT_KEY_LEFT:
            level=(level+leveln-1)%leveln;
			stage=0;
            break;
        case GLUT_KEY_RIGHT:
            level=(level+1)%leveln;
			stage=0;
            break;
    }
    glutPostRedisplay();
}
